package com.example.boot3.service.Impl;

import com.example.boot3.mapper.CardMapper;
import com.example.boot3.model.Card;
import com.example.boot3.model.Recharge;
import com.example.boot3.model.Refuel;
import com.example.boot3.service.CardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.text.html.parser.Parser;
import java.util.List;

/**
 * @author 邹成明
 */
@Service
public class CardServiceImpl implements CardService {

    @Autowired
    private CardMapper cardMapper;

    @Override
    public List<Card> getFuelCardsList() {
        return cardMapper.getFuelCardsList();
    }

    @Override
    public List<Recharge> getRechargeList() {
        return cardMapper.getRechargeList();
    }

    @Override
    public List<Refuel> getRefuelList() {
        return cardMapper.getRefuelList();
    }

    @Override
    public Integer addCard(Card card) {
        Integer result = cardMapper.addCard(card);
        return result;
    }

    @Override
    public Integer rechargeCard(Recharge recharge) {
        Integer result1 = cardMapper.rechargeCard(recharge);
        Integer result2 = cardMapper.addBalance(recharge.getCard_id(), recharge.getRecharge_amount());

        Integer result = result1 & result2;
        return result;
    }

    @Override
    public Integer applyRefuel(Refuel refuel) {
        Integer result1 = cardMapper.applyRefuel(refuel);
        Integer result2 = cardMapper.reduceBalance(refuel.getCard_id(), refuel.getRefuel_amount());

        Integer result = result1 & result2;
        return result;
    }


}
